<template>
    <div>
      <!-- 地图容器 -->
      <div id="map" class="map"></div>
      <!-- 左侧机构树 -->
      <div class="map-btn-box" v-if="isShowZoomTool">
          <div class="map-btn" title="放大" @click="zoomMap(1)"><i class="el-icon-plus"></i></div>
          <div class="map-btn" title="缩小" @click="zoomMap(2)"><i class="el-icon-minus"></i></div>
          <div class="map-btn" title="复位" @click="restcenter()"><i class="iconfont iconfuwei"></i> </div>
      </div>
    </div>
   
</template>
<script>
// 映入css文件、
import "ol/ol.css";
import ZMap from "../../Utils/ol/zMap"

export default {
  props: ["zoom", "center", "isShowBaseMap","isShowZoomTool"],
  data() {
    return {
      map: null
    };
  },
  mounted() {
    this.initMap();
  },
  methods: {
    initMap() {
      this.map = new ZMap({
        target:"map",
        center:this.center||config.center,
        zoom: this.zoom || config.zoom
      })
      if(this.isShowBaseMap)
        this.map.tiandituVetorMap(true)
    },
    /**
     * 地图缩放事件
     */
    zoomMap(type){
      let view = this.map.map.getView()
      let zoom = view.getZoom()
      if(type==1){
        view.setZoom(zoom+1)
      }else{
        view.setZoom(zoom-1)
      }
    },
    /**
     * 复位事件
     */
    restcenter(){
      this.map.restMap({
        center:this.center||config.center,
        zoom: this.zoom || config.zoom
      })
    },
  }
};
</script>
<style>
.map {
  width: 100%;
  height: 100%;
}
.map-btn-box{
  background: white;
  border-radius: 3px;
  margin-bottom: 10px;
  border-color: #e9e9e9;
  position: relative;
  top: -99%;
  left: 10px;
  width: 28px;
}
.map-btn{
    height: 25px;
    width: 25px;
    line-height: 25px;
    background: white;
    text-align: center;
    border-radius: 5px;
    border-bottom: 1px solid #e9e9e9;
    color: black;
}
.map-btn:hover{
  color: #409EFF;
  cursor: pointer;
}
</style>


